// pages/distribution/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    privacyState:true,
    balance:800.00,
    ratio:'8%',
    showBalanceText:'***',
    showRatioText:'***',
    balance:wx.getStorageSync('balance'),
    points:wx.getStorageSync('points')
  },
  addBalance(){
    var balance = wx.getStorageSync('balance');
    var newBalance = Number(balance + 5000);
    wx.setStorageSync('balance', newBalance)
    this.setData({
      balance:newBalance
    })
  },
  addPoints(){
    var points = wx.getStorageSync('points');
    var newPoints = Number(points + 5000);
    wx.setStorageSync('points', newPoints)
    this.setData({
      points:newPoints
    })
  },
  reset(){
    wx.showModal({
      title: '提示',
      content: '请确认是否重置本次测试，所有测试数据将被清空！',
      complete: (res) => {
        if (res.confirm) {
          wx.setStorageSync('balance', 0)
          wx.setStorageSync('points', 0)
          this.setData({
            balance:0,
            points:0
          })
        }
      }
    })
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
  privacy(){
    this.setData({
      privacyState:!this.data.privacyState
    })
    if(!this.data.privacyState){
      this.setData({
        showBalanceText:this.data.balance,
        showRatioText:this.data.ratio
      })
    }else{
      this.setData({
        showBalanceText:'***',
        showRatioText:'***'
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      privacyState:true,
      showBalanceText:'***',
      showRatioText:'***'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})